/*
 * @Author: Clark
 * @Email: haixuanwoTxh@gmail.com
 * @Date: 2021-11-27 17:26:26
 * @LastEditors: Clark
 * @LastEditTime: 2021-12-10 14:59:40
 * @Description: file content
 */

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QtNetwork>
#include <QDebug>

#include "logupwindow.h"
#include "talkwindow.h"
#include "talkprotocol.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

/**
 * @brief 客户端登录状态
 *
 */
typedef enum{
    UNLOGGED,
    LOGGED,
}LoginStatus;

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private:

    bool connect_server();
    void show_self();
    void send_logup_message(QString user, QString passwd);
    void send_talk_msg(uint32_t userID, QString sendStr);

private slots:
    void tcp_connected_callback();
    void tcp_disconnected_callback();
    void data_received_callback();

    void on_pushButtonReconnect_clicked();

    void on_pushButtonLogup_clicked();

    void on_pushButtonLogin_clicked();

private:
    Ui::MainWindow *ui;
    logupwindow    *logupUi;
    talkwindow     *talkUi;

    QTcpSocket *tcpSocket;
    LoginStatus loginStatus;
    QString userName;

    TalkProtocol tp;
    //void keyPressEvent(QKeyEvent *event);
};
#endif // MAINWINDOW_H
